package com.ss.android.b.b;

import android.content.Context;
import android.os.Environment;

import com.bytedance.common.utility.Logger;
import com.ss.android.common.util.ToolUtils;

import java.io.File;

public final class BaseVideoManager {
    public String a;
    public String b;
    private String c;
    private String d;
    private String e;
    private String f;
    private static volatile boolean g;

    static {
        g = false;
    }

    public BaseVideoManager(Context arg2) {
        this(arg2, (byte) 0);
    }

    private BaseVideoManager(Context arg5, byte arg6) {
        File v0_1;
        String v3 = null;

        arg5.getApplicationContext();
        this.c = arg5.getPackageName();
        this.d = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + this.c + "/cache/";
        Logger.d("BaseVideoManager", "mCacheDir = " + this.d);
        try {
            this.f = ToolUtils.getInternalCacheDir(arg5);
        } catch (Exception v0) {
            this.f = v3;
        }

        Logger.d("BaseVideoManager", "mInternalCacheDir = " + this.f);
        this.b = !android.support.design.a.isTextEmpty(this.f) ? this.f + "/hashedvideos/" : v3;
        this.a = this.d + "hashedvideos/";
        this.e = this.d + "tmpvideos/";
        new StringBuilder().append(Environment.getExternalStorageDirectory().getPath()).append("/Android/data/com.ss.spipe/cache/spipevideo");
        if (b()) {
            v0_1 = new File(this.d);
            if (!v0_1.exists()) {
                v0_1.mkdirs();
            }

            v0_1 = new File(this.a);
            if (!v0_1.exists()) {
                v0_1.mkdirs();
            }

            v0_1 = new File(this.e);
            if (v0_1.exists()) {
            } else {
                v0_1.mkdirs();
            }
        }

        try {
            if (android.support.design.a.isTextEmpty(this.b)) {
                return;
            }

            v0_1 = new File(this.b);
            if (v0_1.exists()) {
                return;
            }

            v0_1.mkdirs();
        } catch (Exception v0) {
        }
    }

    public final void a() {
        try {
            if (!android.support.design.a.isTextEmpty(this.b)) {
                ToolUtils.d(this.b);
            }

            if (!b()) {
                return;
            }

            ToolUtils.d(this.a);
        } catch (Exception v0) {
        }
    }

    public final boolean a(String arg3) {
        return new File(this.d(arg3)).exists();
    }

    private static boolean b() {
        boolean v0_1;
        try {
            v0_1 = "mounted".equals(Environment.getExternalStorageState());
        } catch (Exception v0) {
            if (Logger.debug()) {
                v0.printStackTrace();
            }

            v0_1 = false;
        }

        return v0_1;
    }

    public static String b(String arg3) {
        String v0;
        int v2 = 2;
        if (arg3 == null || arg3.length() < v2) {
            v0 = "__";
        } else {
            v0 = arg3.substring(0, v2);
            char v1 = arg3.charAt(0);
            char v2_1 = arg3.charAt(1);
            if ((Character.isLetterOrDigit(v1)) && (Character.isLetterOrDigit(v2_1))) {
                return v0;
            }

            v0 = "__";
        }

        return v0;
    }

    public static String c(String arg2) {
        return arg2 + ".mp4";
    }

    public final String d(String arg4) {
        StringBuilder v0 = new StringBuilder(this.a);
        v0.append(b(arg4)).append("/").append(arg4).append(".mp4");
        return v0.toString();
    }
}

